package com.richapp.launcher.database.system.dao;

import android.content.Context;
import android.util.Log;

import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.QueryBuilder;
import com.richapp.launcher.database.system.SystemBaseDao;
import com.richapp.launcher.database.system.mode.ActionInfraredModel;

import java.util.ArrayList;
import java.util.List;

public class ActionInfraredModelDao extends SystemBaseDao<ActionInfraredModel>{


	public ActionInfraredModelDao(Context context) {
		super(context,ActionInfraredModel.class);
	}
	
	public List<ActionInfraredModel> getList(String sceneName){
		List<ActionInfraredModel> list = new ArrayList<ActionInfraredModel>();
		try {
			QueryBuilder queryBuilder = gettOp().queryBuilder();
			queryBuilder.where().eq("sceneName", sceneName);
			queryBuilder.orderBy("orderNumber",true);
			list = queryBuilder.query();
		} catch (Exception e) {
			Log.e(getClass().getName(), e.getMessage());
		}
		return list;
	}

	public void del(String sceneName){
		try {
			DeleteBuilder deleteBuilder = gettOp().deleteBuilder();
			deleteBuilder.where().eq("sceneName",sceneName);
			deleteBuilder.delete();
		} catch (Exception e) {
			Log.e(getClass().getName(), e.getMessage());
		}
	}


	public void delByUNameAndScentName(String sceneName,String userName){
		try {
			DeleteBuilder deleteBuilder = gettOp().deleteBuilder();
			deleteBuilder.where().eq("sceneName",sceneName).and().eq("userName",userName);
			deleteBuilder.delete();
		} catch (Exception e) {
			Log.e(getClass().getName(), e.getMessage());
		}
	}
	
}
